import 'package:flutter/material.dart';
import 'package:get/get.dart';
import '../../../r.dart';
import '../controllers/dd_block_list_controller.dart';
import '../views/dd_my_block_cell.dart';

class DDBlockListPage extends StatefulWidget {
  const DDBlockListPage({Key? key}) : super(key: key);

  @override
  State<DDBlockListPage> createState() => _DDBlockListPageState();
}

class _DDBlockListPageState extends State<DDBlockListPage> {
  DDBlockListController _controller = DDBlockListController();

  @override
  Widget build(BuildContext context) {
    return GetBuilder<DDBlockListController>(
        init: _controller,
        initState: (state) {},
        dispose: (state) {},
        builder: (controller) {
          return Scaffold(
            appBar: AppBar(
              backgroundColor: Color(0xFFE7F6FC),
              title: Text(
                'Block List',
                style: TextStyle(fontSize: 18),
              ),
              leading: IconButton(
                icon: Image.asset(R.assetsImagesHomeSecond1),
                onPressed: () {
                  Get.back();
                },
              ),
            ),
            backgroundColor: Color(0xFFE7F6FC),
            body: Obx(
              () => _controller.datas.length == 0
                  ? SafeArea(
                      top: false,
                      child: Column(
                        children: [
                          SizedBox(
                            height: 148,
                          ),
                          Center(
                            child: Image.asset(R.assetsImagesPerson15),
                          )
                        ],
                      ))
                  : Stack(
                      children: [
                        Positioned.fill(
                          child: Image.asset(
                            R.assetsImagesPerson20,
                            fit: BoxFit.fill,
                          ),
                        ),
                        Positioned.fill(
                          child: SafeArea(
                            top: false,
                            child: SingleChildScrollView(
                              child: Padding(
                                padding: const EdgeInsets.all(16.0),
                                child: ListView.builder(
                                    shrinkWrap: true,
                                    physics: NeverScrollableScrollPhysics(),
                                    itemBuilder: (context, index) {
                                      return DDMyBlockCell(
                                        model: controller.datas[index],
                                        onClick: () {
                                          _controller.updateMyBlock(
                                              controller.datas[index]);
                                        },
                                        title: "Unblock",
                                      );
                                    },
                                    itemCount: controller.datas.length),
                              ),
                            ),
                          ),
                        ),
                      ],
                    ),
            ),
          );
        });
  }
}
